﻿using Marmat.Foundation;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Marmat.Template.WinForm
{
    public class SearchControlFilterCollection : ISearchControlFilterCollection
    {
        private readonly SearchControl searchControl;

        public SearchControlFilterCollection(SearchControl searchControl)
        {
            this.searchControl = searchControl;
        }

        //public void Add(ISearchControlItemBase item)
        //{
        //    this.searchControl.AddFilter(item);
        //}

        public void Add<TEntity>()
        {
            this.searchControl.AddFilter<TEntity>();
        }

        public void Add<TEntity>(params string[] columns)
        {
            this.searchControl.AddFilter<TEntity>(columns);
        }

        public void Add<TEntity>(Expression<Func<TEntity, object>> expression)
        {
            this.searchControl.AddFilter(expression);
        }

        public void AddField(string name, string caption, Type dataType, string condition = null)
        {
            this.searchControl.AddField(name, caption, dataType, condition);
        }

        public void AddGroup(string name, string caption, string condition)
        {
            this.searchControl.AddGroup(name, caption, condition);
        }

        public void Clear()
        {
            this.searchControl.searchControl1.Columns.Clear();
        }

        public IEnumerator<ISearchControlFilter> GetEnumerator()
        {
            throw new NotImplementedException();
        }

        public void Remove(string name)
        {
            this.searchControl.searchControl1.Columns.Remove(this.searchControl.searchControl1.Columns.FirstOrDefault(x => x.Name == name));
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }
    }
}
